package cn.pinyuan.news.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.pinyuan.news.bean.NewsUser;
import cn.pinyuan.news.service.NewsUserService;

@Controller
public class NewsUserController {

	@Autowired
	private NewsUserService newsUserService;
	
	// 登陆页面
	@RequestMapping("/login")
	public String getLogin() {
		return "jsp/login";
	}
	
	// 登陆验证用户名和密码
	@RequestMapping("/checkLogin")
	public String checkLogin(Model model,String username,String password) {
		if(username != null && password != null) {
			model.addAttribute("username", username);
			model.addAttribute("password", password);
		}
		return "jsp/loginerror";
	}
	
	// 注册页面
	@RequestMapping("/regist")
	public String Regist() {
		return "jsp/regist";
	}
	
	// 注册写入数据库
	@RequestMapping("/doRegist")
	public String doRegist(NewsUser newsUser,Model model) {
		newsUserService.Regist(newsUser);
		return "jsp/success";
	}
}
